package st.magnuzon.books.client.scaffold;

import st.magnuzon.books.client.scaffold.ioc.DesktopInjectorWrapper;
import st.magnuzon.books.client.scaffold.ioc.InjectorWrapper;
import st.magnuzon.books.client.scaffold.ioc.ViewerInjectorWrapper;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Application for browsing entities.
 */
public class Scaffold implements EntryPoint {
	final private InjectorWrapper injectorWrapper = GWT.create(DesktopInjectorWrapper.class);
	final private InjectorWrapper injector2Wrapper = GWT.create(ViewerInjectorWrapper.class);
	private final AuthServiceAsync authService = GWT.create(AuthService.class);

	public void onModuleLoad() {
		/* Get and run platform specific app */
		Panel root = RootPanel.get("viewer");
		if (root != null) {
			injector2Wrapper.getInjector().getScaffoldApp().run();
		} else {
			injectorWrapper.getInjector().getScaffoldApp().run();
		}

		authService.retrieveUsername(new AsyncCallback<String>() {
			public void onFailure(Throwable caught) {
			}

			public void onSuccess(String result) {
			}
		});
	}
}